# coding:utf-8
# 王一舟
# demo_3关键字封装.py

from deepdiff import DeepDiff


def assert_DeepDiff_json(**kwargs):
    '''
    对比2个数据的差异
    :param json1:旧参数
    :param json2:新参数
    :param 忽略排序: ignore_order=True , 默认Flase
    :param 忽略大小写:ignore_string_case=True 默认Flase
    :param 忽略字段:exclude_paths={} 默认None
    :return:
    '''

    json1 = kwargs["json1"]
    json2 = kwargs["json2"]

    # 对比条件,可能没有传递,用 get()
    # 过滤条件可以组装起来,变成 key : value的形式
    filters = {
        "ignore_order": kwargs.get("忽略排序", False),
        "ignore_string_case": kwargs.get("忽略大小写", False),
        "exclude_paths": kwargs.get("忽略字段", None)
    }

    diff_data = DeepDiff(json1,json2,**filters)

    #断言 #因为期望值是空{},所以是反着来判断
    assert not diff_data , f"DeepDiff断言失败:{diff_data}"
    return diff_data

if __name__ == '__main__':

    json1 = {"name":"wyz","age":18}
    json2 = {"name":"wyz","age":20}

    data = {"json1":json1,"json2":json2,"忽略字段":{"age"}}
    assert_DeepDiff_json(**data,)

    diff_data = {}

    if not diff_data :
        print("我是真")
    else:
        print("我是假")

